<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
        <!--工具栏-->
        <el-card>
        <div class="head-container">
          <div v-if="crud.props.searchToggle">
            <!-- 搜索 -->
            <el-input
              v-model="query.keyword"
              clearable
              size="small"
              placeholder="输入邀请码"
              style="width: 200px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
            <rrOperation />
          </div>
          <crudOperation show="" :permission="permission" />
        </div>
      </el-card>
        <el-card style="margin-top:20px;">
          <!--表格渲染-->
        <el-table :header-row-class-name="'table_head'"  ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
          <el-table-column :show-overflow-tooltip="true" prop="actCode" label="邀请码" />
          <el-table-column prop="useTime" label="使用时间" />
        </el-table>
        </el-card>
        <!--分页组件-->
        <pagination />
    </el-row>
  </div>
</template>

<script>
import { uploadFile } from '@/api/admin.js'
import { isvalidPhone } from '@/utils/validate'
import { getDepts, getDeptSuperior } from '@/api/system/dept'
import { getAll, getLevel } from '@/api/system/role'
import { getAllJob } from '@/api/system/job'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'
import Treeselect from '@riophae/vue-treeselect'
import { mapGetters } from 'vuex'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
let userRoles = []
let userJobs = []
const defaultForm = { id: null, nickname: null, avatar: null, userInfo: null }
export default {
  name: 'InvitationCode',
  components: { Treeselect, crudOperation, rrOperation, udOperation, pagination, DateRangePicker },
  cruds() {
    return CRUD({ title: '作者',optShow: {edit: false,add:true,del:true},  url: 'api/act/code/list',methodStr: 'post', dataStr:['data','codeList']})
  },
  mixins: [presenter(), header(),form(defaultForm), crud()],
  // 数据字典
  dicts: ['author_sex'],
  data() {
    // 自定义验证
    const validPhone = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入电话号码'))
      } else if (!isvalidPhone(value)) {
        callback(new Error('请输入正确的11位手机号码'))
      } else {
        callback()
      }
    }
    return {
      height: document.documentElement.clientHeight - 180 + 'px;',
      defaultProps: { children: 'children', label: 'name', isLeaf: 'leaf' },
      img_loading: false,
      permission: {
        add: ['admin', 'user:add'],
        edit: ['admin', 'user:edit'],
        del: ['admin', 'user:del']
      },
      rules: {
        nickname: [
          { required: true, message: '请输入作者昵称', trigger: 'blur' },
        ],
        avatar: [
          { required: true, message: '请上传作者头像', trigger: 'blur' },
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  created() {
    this.crud.msg.add = '作者创建成功'
  },
  mounted: function() {
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  methods: {
    uploadRequest(params) {
      const data = new FormData()
      data.append('file', params.file)
      this.img_loading = true
      uploadFile(data).then(res => {
        this.img_loading = false
        if (res && res.data && res.data.length) {
          this.$set(this.form, 'avatar', res.data[0])
        }
      })
    },
    // 禁止输入空格
    keydown(e) {
      if (e.keyCode === 32) {
        e.returnValue = false
      }
    },
    checkboxT(row, rowIndex) {
      return row.id !== this.user.id
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  ::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
    height: 30px;
    line-height: 30px;
  }
  .tab_avatar{
    width: 60px;
  }
  .avatar-uploader,.el-upload {
      border: 1px solid #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
      width: 178px!important;
      height: 178px;
    }
    .avatar-uploader:hover,.el-upload:hover {
      border-color: #409EFF;
    }
    .upload-text {
      font-size: 14px;
      color: #8c939d;
      line-height: 178px;
      text-align: center;
      margin: 0 auto;
    }
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
    .container{
      padding-bottom: 30px;
    }
    .table_head{
      background: #fafafa;
    }
</style>
<style>
  .dialog-form .el-input{
    width: 300px;
  }
</style>
